package cn.gem.rainbow.cfg.web;

import cn.gem.rainbow.cfg.SystemParam;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author lzh
 * @date 2020/8/27 - 9:15
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class Knife4jConfig {

    @Autowired
    private SystemParam systemParam;



    private ApiInfo apiInfo() {
        System.err.println(systemParam.getMaps());
        System.err.println(systemParam.getVarmaplist());
        return new ApiInfoBuilder()
                .title(systemParam.getAppChineseName() + "后台接口文档")
                .description(systemParam.getAppChineseName())
                .termsOfServiceUrl("www.xxx.com.cn")
                .version(systemParam.getAppVersion())
                .contact(new Contact(systemParam.getAppDeveloper(), null, "1131201834@qq.com"))
                .build();
    }

    @Bean(value = "defaultApi")
    public Docket defaultApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //分组名称
                .groupName("1.X版本接口")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("cn.gem.rainbow.api"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
